package com.tgpms.web.element.controller;

import java.util.Arrays;
import java.util.Map;

import com.tgpms.common.R;
import com.tgpms.common.PageUtils;
import com.tgpms.web.element.entity.WsDoc;
import com.tgpms.web.element.service.WsDocRelService;
import com.tgpms.web.element.service.WsDocService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




/**
 * 附件表
 *
 * @author jl
 * @since 2020-07-13 11:33:15
 */
@Api(value = "WsDocController", tags = "附件表相关接口")
@RestController
@RequestMapping("/ev/wsdoc")
public class WsDocController {
    @Autowired
    private WsDocService wsDocService;
    @Autowired
    private WsDocRelService wsDocRelService;

    /**
     * 根据业务表主键DOC_REL_ID查询附件信息
     */
    @ApiOperation(value = "根据业务表主键DOC_REL_ID查询附件信息", notes = "根据业务表主键DOC_REL_ID查询附件信息", httpMethod = "POST")
    @PostMapping("/getWsDocByDocRelId")
    public R getWsDocByDocRelId(@RequestParam Map<String,Object> params) {
        String docRelId =(String) params.get("docRelId");
        if (StringUtils.isBlank(docRelId)) {
            return R.error("业务主键id不能为空!");
        }
        PageUtils page = wsDocService.getWsDocByDocRelId(docRelId, params);
        return R.ok(page);
    }

    /**
     * 带条件分页查询wsDoc
     */
    @GetMapping("/list")
    @ApiOperation(value = "带条件分页查询wsDoc", notes = "带条件分页查询wsDoc", httpMethod = "GET")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wsDocService.queryPage(params);

	    return R.ok(page);
    }


    /**
     * 根据主键查询wsDoc
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据主键查询wsDoc", notes = "根据主键查询wsDoc", httpMethod = "GET")
    public R info(@PathVariable("id") String id){
		WsDoc wsDoc = wsDocService.getById(id);

        return R.ok(wsDoc);
    }

    /**
     * 新增wsDoc
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增wsDoc", notes = "新增wsDoc", httpMethod = "POST")
    public R save(@RequestBody WsDoc wsDoc){
		wsDocService.save(wsDoc);

        return R.ok();
    }

    /**
     * 修改wsDoc
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改wsDoc", notes = "修改wsDoc", httpMethod = "PUT")
    public R update(@RequestBody WsDoc wsDoc){
		wsDocService.updateById(wsDoc);

        return R.ok();
    }

    /**
     * 删除wsDoc
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "根据主键id删除wsDoc", notes = "根据主键id删除wsDoc", httpMethod = "DELETE")
    public R delete(@RequestParam("id")String id){
		if (wsDocService.removeById(id)){
            // 删除附件关联表数据
            wsDocRelService.removeById(id);
            return R.ok();
        }
       return R.error("删除附件失败!");
    }

}
